package Logic;

import java.io.IOException;

import Model.fontWebsite;

public class sourceGatherer 
{
	private static sourceGatherer instance = null;
	private webInterface _web;
	private normModule _norm;
	private String _currentURL;
	private fontWebsite _font;
	
	private sourceGatherer() 
	{
		_norm = normModule.getInstance();
		_web = webInterface.getInstance();
	}
	
	public static sourceGatherer getInstance() 
	{
		if(instance == null) 
		{
		   instance = new sourceGatherer();
		}
		return instance;
	}
	
	public void setCurrentURL ( String url )
	{
		_currentURL = url;
	}

	public String getTitle () 
	{
		try
		{
			return _norm.getNormalizedText(1, _font, this.getHTML());
		}
		catch( IOException e )
		{
			System.out.print("There is a problem with the webInterface. \n");
			return "There is a problem with the Title. \n";
		}
	}
	public String getBody ()
	{
		try
		{
			return _norm.getNormalizedText(2, _font, this.getHTML());
		}
		catch( IOException e )
		{
			System.out.print("There is a problem with the webInterface. \n");
			return "There is a problem with the Body. \n";
		}
	}
	public String getDate () 
	{
		try
		{
			return _norm.getNormalizedText(3, _font, this.getHTML());
		}
		catch( IOException e )
		{
			System.out.print("There is a problem with the webInterface. \n");
			return "There is a problem with the Date. \n";
		}
		
	}
	
	private String getHTML() throws IOException
	{
		try
		{
			return _web.getHtml(_currentURL);
		}
		catch( IOException e )
		{
			System.out.print("There is a problem with the webInterface. \n");
			return "There is a problem with the webInterface. \n";
		}
	}
	
	public void startFontTest( String regTex, String regTex2, String regDat)
	{
		_font = new fontWebsite();
		_font.setRuleBody(regTex, regTex2);
		
	}
	
	
	
	
}
